﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using YunSteelyard.util;

namespace YunSteelyard
{
    public partial class Form1 : Form
    {
        YunSteelyard.UserInfo userInfo = new YunSteelyard.UserInfo();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();

            try
            {
                if (ports.Length == 0)
                {
                    MessageBox.Show("没有检测到串口");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "提示信息");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //手机号
            String uMobile = textBox1.Text;
            //密码
            String uPassword = textBox2.Text;
            String sql = "select * from user_info where mobile='" + uMobile + "' and password='" + uPassword + "'";//在这儿写sql语句
            MysqlUtil db = new MysqlUtil();
            DataSet ds = db.GetDataSet(sql);
            int dt = ds.Tables[0].Rows.Count;
            if (dt > 0)
            {
                

                //登陆信息
                string id = Convert.ToString(ds.Tables[0].Rows[0]["ID"]);
                string name = Convert.ToString(ds.Tables[0].Rows[0]["userName"]);
                userInfo.Person_ID = id;
                userInfo.Person_Name = name;

                Form2 f2 = new Form2(userInfo);
                this.Hide();
                f2.Show();
            }
            else
            {
                MessageBox.Show("登陆失败");
            }
            }
    }
}
